/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cronus.server;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.File;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.Exception;


/**
 *
 * @author Jannick
 */
public class Log {
    
    private Main main;
    private String dateTime;
    private String logDate;
    private int id;
    private String line;
    private File file;
    private PrintWriter writer;
    private FileWriter filewriter;
    private StringBuffer buffer;
    
    public Log( Main main ){
        this.main = main;
    }
    
    public void addToLog( String line ){
        //Haal datum en tijd op en zet in volgorde Jaar-Maand-Dag Uur-Minut-Seconde.
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DateFormat datum = new SimpleDateFormat("yyyy-MM-dd");
        
        Date dag = new Date();
        Date date = new Date();
        this.dateTime = dateFormat.format(date);
        this.logDate = datum.format(dag); 
        //haal id en line op.
        this.id = id;
        this.line = line;
        String t = "";
        try {
            file = new File("logs\\log" + logDate + ".txt");
            filewriter = new FileWriter(file, true);
            writer = new PrintWriter(filewriter);
            t += ("" + dateTime + " " + line + "\n");
            writer.println(t);
        } catch(java.io.IOException ex){
            ex.printStackTrace();
        } finally{
            
                writer.close();
            
            
        }
         
        
        
    }
}
